<template>
	<view class="wrap">
		<template v-if="isHasDataFlag">
			<view class="listWrap">
				<my-cls 
					:clsList="clsList" 
					@goClsDet="goClsDet"
				></my-cls>
			</view>
		</template>
		<template v-else-if="isHasDataFlag == false">
			<no-data></no-data>
		</template>
	</view>
</template>

<script>
	import MyCls from './components/MyCls.vue'
	import { getMyClassList,getStuList } from '@/api/zhuxue'
	export default {
		components:{
			MyCls
		},
		data() {
			return {
				isHasDataFlag:null,
				showAlertFlag:false,
				levelB:'',
				clsList:[],
				currClsName:'',
				checkTxt:'',
				isDisabledFlag:false,
				leaderId:0,
				classId:0,
				opt:'',
				gzId:0,
				canViewCpNum:0
			}
		},
		onLoad(options){
			this.levelB = options.levelB;
		},
		onShow(){
			this.loadMyClassList();
		},
		onPullDownRefresh : function(){
			this.loadMyClassList();
			uni.stopPullDownRefresh();
		},
		onUnload(){
			uni.removeStorageSync('stuList');
		},
		methods: {
			loadMyClassList(){
				let field = { account:uni.getStorageSync('token'),showGradeTag:0 };
				let contentStr = this.crypto.encrypt(JSON.stringify( field )); 
				getMyClassList({content:contentStr}).then(res=>{
					this.isHasDataFlag = true;
					this.clsList = res.data.datas.classList;
				}).catch(err=>{
					this.isHasDataFlag = false;
					//console.log(err)
				});
			},
			//查看班级学生列表
			goClsDet(item){
				let currClsName = item.levelC  + item.levelD + '班';
				let field = { classId:item.classId };
				let contentStr = this.crypto.encrypt(JSON.stringify( field )); 
				uni.showLoading({ title: '加载中...', mask: true }); 
				getStuList({content:contentStr}).then(res=>{
					var tmpRes = res.data.datas;
					uni.setStorageSync('stuList',tmpRes);
					uni.navigateTo({
						url:'/pages/subIndex/stuList/stuList?currClsName=' + currClsName + '&stuName=' + '&fromPage=myClsPage'
					})
				}).catch(err=>{
					this.util.showToast('当前班级暂无学生')
					uni.removeStorageSync('stuList');
				});
			}
		}
	}
</script>

<style lang="scss">
	.listWrap{
		padding: 30rpx 30rpx 0;
	}
	page{
		background: $pss-bg-primary;
	}
</style>
